/**
 * Created by ebalmes Oct 6, 2009 10:44:13 AM
 * 
 */
package model.table;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.table.AbstractTableModel;

import exceptions.DataException;

import model.DataModel;
import model.types.Patient;

public class SearchPatientTableModel extends AbstractTableModel
{
  String[] columnNames = {"Name", "Taj number", "Date of birth"};
  private List<Patient> rowData;
  private static Logger logger = Logger.getLogger(SearchPatientTableModel.class.getName()); 
  
  public SearchPatientTableModel() {
    rowData = new ArrayList<Patient>();
  }
  
  public int getColumnCount() {
    return columnNames.length;
  }
  
  public int getRowCount() {
    return rowData.size();
  }
  
  public Object getValueAt(int row, int column) {
    Patient patient = rowData.get(row);
    switch (column) {
    case 0: return patient.getName();
    case 1: return patient.getTajNumber();
    case 2: return patient.getDateOfBirth();
    }
    return "";
  }
  
  public String getColumnName(int index) {
    return columnNames[index];
  }
  
  public void searchFieldChanged(String searchText) {
   rowData = DataModel.getInstance().getPatients(searchText);
   fireTableDataChanged();
  }

  public void clearTableModel() {
    rowData.clear();
    fireTableDataChanged();
    logger.log(Level.INFO, "Table model cleared.");
  }
}
